package com.focus.xyz.mobile.cases;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.core.common.webdriver.SeleConst;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.mobile.pages.MHomePage;
import com.focus.xyz.mobile.pages.MLoginPage;
import com.focus.xyz.mobile.pages.MProdCataPage;
import com.focus.xyz.mobile.pages.MProdInfoPage;
import com.focus.xyz.union.action.KeyWordAction;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

/**
 * Created by chenmeng on 2016/7/25.
 */
public class MobileTest extends TC{

    private Action action;
    private WebDriver driver;

    @Parameters({"nodeUrl","device","browser"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String device,String browser) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getDevice(device).getBrowser(browser);
        super.init(driver);
        action = new Action(driver);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }

    @Test(description = "触屏会员注册")
    public void test() throws Exception{
        /*打开主页*/
        MHomePage mHome = new MHomePage(driver,action);
        mHome.openMainPage();
        /*点击会员菜单*/
        mHome.clickMemMenu("会员");
        /*打开登录页，登录会员*/
        MLoginPage mLogin = new MLoginPage(driver,action);
        mLogin.login("18811112222","ins1234");
        action.pause(1000l);
        /*点击产品菜单*/
        mHome.clickMemMenu("产品");
        action.pause(1000l);
        /*点击产品目录*/
        MProdCataPage mCata = new MProdCataPage(driver,action);
        mCata.clickCatalog("国内旅行保险");
        action.pause(1000l);
        /*选择产品*/
        mCata.clickProd("[促销版]安联安途中国境内游经典款");
        action.pause(1000);
        /*投保*/
        MProdInfoPage mProd = new MProdInfoPage(driver,action);
        mProd.toubao();
    }

    public static void main(String[] args) {
        for(int i = 0;i<2;i++){
            new Thread(new MyThread()).start();
        }
    }

}
class MyThread implements Runnable{
    public void run() {
        try{
            WebDriver driver = DriverFactory.getInstance().getMultiDriver(null).getDevice("iphone6").getBrowser("default");
            Action action = new Action(driver);
            MHomePage mHome = new MHomePage(driver,action);
            mHome.openMainPage();
            mHome.clickMemMenu("会员");
            MLoginPage mLogin = new MLoginPage(driver,action);
            mLogin.login("18811112222","ins1234");
            mHome.clickMemMenu("产品");
            action.capScreen("E:/touch" + Thread.currentThread().getName() + ".png");
            driver.quit();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
//            ProcessUtil.closeBrowser("chrome");
        }

    }
}
